
# include "dfxWaveDataProvider.h"

namespace DFX
{
    Int32 DecodingProvider::StreamWaveData(UInt32 size)
    {
        UInt32 oldSize = mWaveData.size();

        if (size > oldSize)
        {
            mWaveData.resize(size);
            
            for (UInt32 i = 0; i < size - oldSize; i++)
                mWaveData[i + oldSize] = 0;
        }

        if (mEOF)
            return 0;

        UInt32 bytesRead = 0;

        while (bytesRead < size)
        {
            Int32 ret = ReadFromFile(size, bytesRead);

            if (ret > 0)
            {
                bytesRead += ret;
            }
            else if (ret == 0)
            {
                mEOF = true;

                if (mLoop)
                {
                    Seek(0);
                    mEOF = false;
                    continue;
                }

                break;
            }
            else
            {
                Seek(0);
                mEOF = true;
                break;
            }
        }

        return (mWaveDataSize = bytesRead);
    }
}